package xyz.kail.demo.easyrules.hello.annotation;

import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.api.RulesEngineParameters;
import org.jeasy.rules.core.AbstractRulesEngine;
import org.jeasy.rules.core.DefaultRulesEngine;

public class Main {

    public static void main(String[] args) {
        // 事实
        Facts facts = new Facts();
        facts.put("fact", "hello");

        // 规则
        Rules rules = new Rules();
        rules.register(new HelloRule());

        // 规则引擎参数
        RulesEngineParameters parameters = new RulesEngineParameters()
                // 被触发时跳过后面的规则
                .skipOnFirstAppliedRule(true)
                // 失败时跳过后面的规则
                .skipOnFirstFailedRule(true)
                // 一个规则不会被触发跳过后面的规则
                .skipOnFirstNonTriggeredRule(true);

        // 规则引擎
        AbstractRulesEngine rulesEngine = new DefaultRulesEngine(parameters);
        // 监听器
        rulesEngine.registerRuleListener(new HelloListener());
        // 引擎监听器
        rulesEngine.registerRulesEngineListener(new HelloEngineListener());

        // 触发规则
        rulesEngine.fire(rules, facts);
    }

}
